<?php

/**
 * registration actions.
 *
 * @package    sf_sandbox
 * @subpackage registration
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class registrationActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    //$this->forward('default', 'module');
	$this->redirect('registration/new');
  }
  
  public function executeNew(sfWebRequest $request)
  {
     $this->form = new registrationForm();
		if($request->isMethod('POST'))
		{
			$this->form->bind($request->getParameter($this->form->getName()));
			if($this->form->isValid())
			{
				$sf_guard_user = $this->form->save();
			}
		}
  }
  
  	public function executeActivateAccount(sfWebRequest $request)
	{
		$hash = $this->getRequestParameter('hash');
		$timestamp = $this->getRequestParameter('timestamp');

		$c = new Criteria();
		$c->add(sfGuardUserPeer::MD5_KEY , $hash);
		$c->add(sfGuardUserPeer::CREATED_AT, base64_decode($timestamp));
		$c->add(sfGuardUserPeer::IS_ACTIVE, 0); // the user should be inactive here
		$guard_user = sfGuardUserPeer::doSelectOne($c);

		$this->forward404Unless($guard_user);
		$guard_user->setIsActive(true); // activate the account
		$guard_user->setMd5Key(null);
		$guard_user->save();

		$this->getUser()->signin($guard_user, false); // automatically signin when the form is submitted
	}
}
